<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <title>计步建议</title>
        <link rel="stylesheet" href="css/pingce.css">
        <script src="js/jquery-3.3.1.min.js"></script>
    </head>              
<body>
<div class="walk">
    <!-- 昨日步数 -->
    <div class="count">
        <div class="last">
          <span class="counts" id="last_walk"></span>
          <span class="info">昨日步数</span>
        </div>
        <div class="avg">
                <span class="counts"id="avg_walk"></span>
                <span class="info">平均步数</span>
        </div>
    </div>
    <!-- 行走建议 -->
    <div class="advise">
        <div class="title">行走建议</div>
        <div class="suggest"></div>
    </div>
</div>
<script>
// 页面数据获取及建议
$.ajax({
        type: "get",//请求方式
        url: "/user/getwalksdata",//地址，就是json文件的请求路径
        dataType: "json",//数据类型可以为 text xml json  script  jsonp
        success: function(result){//返回的参数就是 action里面所有的有get和set方法的参数
            var walk_sort=0;
            var arrs=[];
            console.log(result)
            if(result.length>0){
                $("#last_walk").text(result[0].step_count);
                result.forEach(element => {
                    walk_sort +=parseInt((element.step_count)/(result.length));
                });
                $("#avg_walk").text(walk_sort);
                $.ajax({
                    type:"get", 
                    url:'/user/getwalkword?walk_sort='+walk_sort,
                    dataType:"json",
                    success:function(result){
                        if(walk_sort==0) $(".suggest").text('暂无数据！');
                        $(".suggest").text(result[0].wk_radio_desc);
                    }
                
                })
            }
            else{
                $(".counts").text('0');
                $(".suggest").text('暂无数据！');
            }
    }})
</script>
</body>
</html>